<script setup lang="ts">
import ReCol from "@/components/ReCol";
import { ref } from "vue";
import { formRules } from "./utils/rule";
import { FormProps } from "./utils/types";
import Segmented from "@/components/ReSegmented";
import {usePublicHooks} from "@/views/system/hooks";
const { switchStyle } = usePublicHooks();

const props = withDefaults(defineProps<FormProps>(), {
  formInline: () => ({
    id: 0,
    currency_from: "USD",
    currency_to: "USD",
    rate: 0.0,
    rate1: 0.0,
    time: '',
    status: 1,
  })
});

const ruleFormRef = ref();
const newFormInline = ref(props.formInline);

function getRef() {
  return ruleFormRef.value;
}

defineExpose({ getRef });

</script>

<template>

  <el-form
    ref="ruleFormRef"
    :model="newFormInline"
    :rules="formRules"
    label-width="86px"
  >
    <el-row :gutter="30">

      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="原币" prop="currency_from">
          <el-select
            v-model="newFormInline.currency_from"
            placeholder="请输入原币"
            class="!w-full"
            clearable
          >
            <el-option class="w-full"
                       v-for="(item, index) in [{value: 'USD',label: 'USD'},{value: 'CNY',label: 'CNY'}]"
                       :key="index"
                       :label="item.label"
                       :value="item.value"
            />
          </el-select>
        </el-form-item>
      </re-col>
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="目的币" prop="currency_to">
          <el-select
            v-model="newFormInline.currency_to"
            placeholder="请输入原币"
            class="!w-full"
            clearable
          >
            <el-option class="w-full"
                       v-for="(item, index) in [{value: 'USD',label: 'USD'},{value: 'CNY',label: 'CNY'}]"
                       :key="index"
                       :label="item.label"
                       :value="item.value"
            />
          </el-select>
        </el-form-item>
      </re-col>
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="直接汇率" prop="rate">
          <el-input-number v-model="newFormInline.rate" clearable placeholder="支持两个小数" class="!w-full" :min="0.01" :step="0.01" controls-position="right" />
        </el-form-item>
      </re-col>
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="间接汇率" prop="rate2">
          <el-input-number v-model="newFormInline.rate2" clearable placeholder="支持两个小数" class="!w-full" :min="0.01" :step="0.01" controls-position="right" />
        </el-form-item>
      </re-col>


      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="生效日期" prop="time">
          <el-date-picker
            v-model="newFormInline.time"
            type="daterange" value-format="YYYY-MM-DD" format="YYYY-MM-DD"
            range-separator="~"  class="!w-full"
            start-placeholder="Start date"
            end-placeholder="End date"
          />
        </el-form-item>
      </re-col>

      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="用户状态">
          <el-switch
            v-model="newFormInline.status"
            inline-prompt
            :active-value="1"
            :inactive-value="0"
            active-text="启用"
            inactive-text="停用"
            :style="switchStyle"
          />
        </el-form-item>
      </re-col>
    </el-row>
  </el-form>

</template>
